import { request } from '@/utils/request'
import type {
  FoodPickupRequest,
  FoodPickupResponse,
  FoodPickupOrder
} from '@/types/api/food-pickup'

// 创建外卖代取订单
export const createFoodPickupOrder = (data: FoodPickupRequest): Promise<FoodPickupResponse> => {
  return request({
    url: '/food-pickup/create',
    method: 'POST',
    data
  })
}

// 获取外卖代取订单列表
export const getFoodPickupOrders = (): Promise<{ success: boolean; data: FoodPickupOrder[]; message: string }> => {
  return request({
    url: '/food-pickup/orders',
    method: 'GET'
  })
}

// 获取外卖代取订单详情
export const getFoodPickupOrderDetail = (orderId: string): Promise<{ success: boolean; data: FoodPickupOrder; message: string }> => {
  return request({
    url: `/food-pickup/order/${orderId}`,
    method: 'GET'
  })
}

// 取消外卖代取订单
export const cancelFoodPickupOrder = (orderId: string): Promise<{ success: boolean; message: string }> => {
  return request({
    url: `/food-pickup/cancel/${orderId}`,
    method: 'PUT'
  })
}

// 上传外卖信息图片
export const uploadFoodImage = (file: File): Promise<{ success: boolean; data: { imageUrl: string }; message: string }> => {
  const formData = new FormData()
  formData.append('image', file)

  return request({
    url: '/food-pickup/upload-image',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

